package com.mxdx.edu.service.impl;

import com.mxdx.edu.dao.StudentDao;
import com.mxdx.edu.enums.DelFlagEnums;
import com.mxdx.edu.model.StudentInfo;
import com.mxdx.edu.model.StlistInfo;
import com.mxdx.edu.service.IStudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 学生service
 *
 * @author howie
 * @date 2018-02-12
 */
@Service
public class StudentServiceImpl implements IStudentService {

	@Resource
	private StudentDao studentDao;

	/**
	 * 保存学生信息
	 * @param studentInfo
	 */
	@Override
	public void save(StudentInfo studentInfo) {
//		studentInfo.setStudentType(StudentTypeEnums.TOURISTS.getCode());
		studentInfo.setCreateDate(new Date());
		studentInfo.setUpdateDate(new Date());
		studentInfo.setDelFlag(DelFlagEnums.NO_DELETE.getCode());
		studentDao.save(studentInfo);
	}

	/**
	 * 通过手机号查询到用户信息返回：false、未查询到返回true
	 * @param param
	 * @return boolean
	 */
	@Override
	public boolean checkStudentByPhoneNumber(Map<String, Object> param) {
		List<Map<String, Object>> list = studentDao.findListByMap(param);
		if(list != null && list.size() > 0){
			return false;
		}
		return true;
	}

	@Override
	public boolean checkLogin(Map<String, Object> param) {
		List<Map<String, Object>> list = studentDao.findListByMap(param);
		if(list != null && list.size() > 0){
			return true;
		}
		return false;
	}

	@Override
	public Map<String, Object> findMapByPhoneNumber(String phoneNumber) {
		Map<String, Object> findMap = new HashMap<>();
		findMap.put("phoneNumber", phoneNumber);
		List<Map<String, Object>> list = studentDao.findListByMapNotStudentType(findMap);
		if(list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public Map<String, Object> findMapByPhoneNumberAndStudentType(String phoneNumber, String studentType) {
		Map<String, Object> findMap = new HashMap<>();
		findMap.put("phoneNumber", phoneNumber);
		findMap.put("studentType", studentType);
		List<Map<String, Object>> list = studentDao.findListByMap(findMap);
		if(list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public void updateStudentInfoByMap(Map<String, Object> param) {
		param.put("updateDate", new Date());
		studentDao.updateStudentInfoByMap(param);
	}

	@Override
	public Map<String, Object> findStudentMapOneByMap(Map<String, Object> param) {
		List<Map<String, Object>> list = studentDao.findListByMap(param);
		if(list != null && list.size() > 0){
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<Map<String, Object>> findListByMap(Map<String, Object> param) {
		return studentDao.findListByMap(param);
	}

	@Override
	public List<Map<String, Object>> findSchoolmateByMap(Map<String, Object> param) {
		return studentDao.findSchoolmateByMap(param);
	}
	@Override
	public List<Map<String, Object>> findFriendsByMap(Map<String, Object> param) {
		return studentDao.findFriendsByMap(param);
	}
	@Override
	public List<Map<String, Object>> findFcirlsByMap(Map<String, Object> param) {
		return studentDao.findFcirlsByMap(param);
	}
	@Override
	public List<Map<String, Object>> findCirlsByMap(Map<String, Object> param) {
		return studentDao.findCirlsByMap(param);
	}
	@Override
	public List<Map<String, Object>> findSfridByMap(Map<String, Object> param) {
		return studentDao.findSfridByMap(param);
	}
	@Override
	public List<Map<String, Object>> findNfridByMap(Map<String, Object> param) {
		return studentDao.findNfridByMap(param);
	}


	@Override
	public List<Map<String, Object>> findCirlsComment(Map<String, Object> param){
		return studentDao.findCirlsComment(param);
	}

	@Override
	public boolean updatePwdByMap(Map<String, Object> param) {
		param.put("updateDate", new Date());
		return studentDao.updatePwdByMap(param) > 0;
	}
	@Override
	public void updateSlistByMap(Map<String, Object> param) {
		param.put("updateDate", new Date());
		studentDao.updateStlistByMap(param);
	}
	/**
	 * 保存新增好友信息
	 * @param stlistInfo
	 */
	@Override
	public void saveStlist(StlistInfo stlistInfo) {
//		studentInfo.setStudentType(StudentTypeEnums.TOURISTS.getCode());
		stlistInfo.setId(stlistInfo.getId());
		stlistInfo.setStudentId(stlistInfo.getStudentId());
		stlistInfo.setStudentTk(stlistInfo.getStudentTk());
		stlistInfo.setStudentFd(stlistInfo.getStudentFd());
		stlistInfo.setStudentFk(stlistInfo.getStudentFk());
		studentDao.saveStlist(stlistInfo);
	}
	/**
	 * 更新好友通过信息
	 */

	@Override
	public boolean saveCirls(Map<String, Object> findMap) {
		int count = studentDao.saveCirls(findMap);
		if (count > 0) {
			return true;
		}
		return false;
	}

	@Override
	public boolean saveComment(Map<String, Object> findMap) {
		int count = studentDao.saveComment(findMap);
		if (count > 0) {
			return true;
		}
		return false;
	}

}
